![]() ![]() ![]() |
X
is a container class
containing other objects, a
and b
are instances of
X
, u
is an identifier and I
is
the iterator class returned by container X
.
expression | return type | operational semantics | assertion/note pre/post-condition | complexity |
---|---|---|---|---|
X()
| . | . | X().size() == 0 | constant |
X(a)
| . | . | a == X(a). | linear |
a.begin()
|
I;
| . |
a.beginRef().copy()
| constant |
a.beginRef()
|
I;
| . | . | constant |
a.beginGeneric()
|
Iterator;
| . | . | constant |
a.end()
|
I;
| . |
a.endRef().copy()
| constant |
a.endRef()
|
I;
| . | . | constant |
a.endGeneric()
|
Iterator;
| . | . | constant |
a.equalTo(b)
|
boolean
| . | . | linear |
a.size()
|
int
| . | . | constant |
a.max_size()
|
int
| . |
size() of the largest possible container
| constant |
a.empty()
|
boolean
|
a.size() == 0
| . | constant |
The member function size()
return the number of elements in
the container.
Its semantics is defined by the rules of constructors, inserts, and erases.
begin()
returns an iterator referring to the first element
in the container.
end()
returns an iterator which is the past-the-end value.
beginRef()
and endRef()
returns corresponding
references to iterators.
Such a reference must be treated as a constant, that is, the position
of the iterator must never be altered, as this might corrupt the container.
Valid use of references to iterators is as in this example.
for (ForwardIterator i = v.begin(); !i.cmp(v.endRef()); i++) { ... }Using endRef() in the comparison makes the loop run faster.
The return values of beginRef() and endRef() can safely by passed on to algorithm function, since all the algorithms always creates a copy of the iterator before modifying the iterator position.
Note: Not all containers support the X() constructer. The sorted
containers Map
, MultiMap
, Set
and
MultiSet
must all be constructed with a predicate object as
argument.
XXX: Suggestion: A default predicate object could be supplied. The
default could then be taken from a public static variable in the container.
![]() ![]() ![]() |